Cov.FamilyClass <- CovInteraction(Homophily.Brexit.ordinal, "Match.subFamClassD")
Homophily4 <- coef(summary(Homophily.Brexit.ordinal)) %>%
data.frame() %>%
tibble::rownames_to_column("term")
#vcov_2 <- vcov(Homophily.Party.ordinal) %>%
#  data.frame() %>%
#  tibble::rownames_to_column("term")
Covariances<-rbind(Cov.Education, Cov.Ethnicity,
Cov.Home, Cov.Gender, Cov.Region, Cov.Religion, Cov.Class,Cov.FamilyClass, Cov.Age, Cov.Income)
InteractionIdentityB<- left_join(Covariances, Homophily4, by = "term")
InteractionIdentityB<- InteractionIdentityB %>%
mutate(term, term = str_replace(term,"Match.GenderD:pastvote_BrexitLeave", "pastvote_BrexitLeave:Match.GenderD"))
InteractionIdentityB<- InteractionIdentityB %>%
mutate(term, Coefficient = str_glue("Remain:{term}"))
InteractionIdentityB<- InteractionIdentityB %>%
mutate(term, Coefficient = str_remove(Coefficient,"Remain:pastvote_Brexit"))
InteractionIdentityB<- InteractionIdentityB %>%
mutate(term, Coefficient = str_remove(Coefficient,"Match."))
InteractionIdentityB<- InteractionIdentityB %>%
mutate(term, Coefficient = str_remove(Coefficient,"D"))
#Obtain coefficents
InteractionIdentityCoefB<- InteractionIdentityB %>%
dplyr::select(Coefficient, Value)
InteractionIdentityCoefB<- InteractionIdentityCoefB %>%
tidyr::separate(col=Coefficient, into=c("type","Coefficient"))
InteractionIdentityCoefB<- InteractionIdentityCoefB %>%
tidyr::spread(type, Value, convert=T)
InteractionIdentityCoefB<- InteractionIdentityCoefB %>%
mutate(Leave= InteractionIdentityCoefB$Remain + InteractionIdentityCoefB$Leave)
#Obtain standard errors
InteractionIdentityCovB<- InteractionIdentityB %>%
dplyr::select(Coefficient, Covariance)
InteractionIdentityCovB<- InteractionIdentityCovB %>%
tidyr::separate(col=Coefficient, into=c("type", "Coefficient"))
InteractionIdentityCovB<- InteractionIdentityCovB %>%
tidyr::spread(type, Covariance, convert=T)
InteractionIdentityCovB<- InteractionIdentityCovB %>%
dplyr::rename("Remain.Cov00"= "Remain" ,
"Leave.Cov01" ="Leave")
InteractionIdentitySEB<- InteractionIdentityB %>%
dplyr::select(Coefficient, Std..Error)
InteractionIdentitySEB<- InteractionIdentitySEB %>%
tidyr::separate(col=Coefficient, into=c("type", "Coefficient"))
InteractionIdentitySEB<- InteractionIdentitySEB %>%
tidyr::spread(type, Std..Error, convert=T)
InteractionIdentitySEB<- InteractionIdentitySEB %>%
dplyr::rename("Remain.SE"= "Remain" ,
"Leave.SE" ="Leave")
InteractionIdentitySE.tidyB<- left_join(InteractionIdentitySEB, InteractionIdentityCovB, by = "Coefficient")
InteractionIdentitySE.tidyB[,2]<-InteractionIdentitySE.tidyB[,2]^2
InteractionIdentitySE.tidyB[,4]<-InteractionIdentitySE.tidyB[,4]*2
InteractionIdentitySE.tidyB<- InteractionIdentitySE.tidyB %>%
mutate(Leave.SE=
sqrt( InteractionIdentitySE.tidyB$Remain.Cov00 +InteractionIdentitySE.tidyB$Leave.SE + InteractionIdentitySE.tidyB$Leave.Cov01))
#Tyding up
InteractionIdentitySE.tidyB <- InteractionIdentitySE.tidyB %>%
dplyr::select( "Name"=Coefficient, ends_with("SE"))
InteractionIdentitySE.tidyB <- InteractionIdentitySE.tidyB %>%
gather(key="level", value = "SE", ends_with("SE"))
InteractionIdentitySE.tidyB <- InteractionIdentitySE.tidyB %>%
mutate(level = str_remove(level, ".SE"))
InteractionIdentitySE.tidyB <- InteractionIdentitySE.tidyB %>%
unite("Name", c(Name, level))
InteractionIdentitySE.tidyB <- InteractionIdentitySE.tidyB %>%
filter(!is.na(SE))
InteractionIdentityCoef.tidyB <- InteractionIdentityCoefB %>%
dplyr::select( "Name"=Coefficient, Remain, Leave)
InteractionIdentityCoef.tidyB <- InteractionIdentityCoef.tidyB %>%
gather(key="level", value = "Coefficient", c(Remain, Leave))
InteractionIdentityCoef.tidyB <- InteractionIdentityCoef.tidyB %>%
unite("Name", c(Name, level))
InteractionIdentityCoef.tidyB <- InteractionIdentityCoef.tidyB %>%
filter(!is.na(Coefficient))
InteractionIdentity.tidyB <- left_join(InteractionIdentitySE.tidyB, InteractionIdentityCoef.tidyB, by = "Name")
InteractionIdentity.tidyB <-InteractionIdentity.tidyB[order(InteractionIdentity.tidyB$Name),]
InteractionIdentity.tidyB2<- InteractionIdentity.tidyB %>%
tidyr::separate(col=Name, into=c("Name","Referendum.Vote"), sep="_")
InteractionIdentity.tidyB2<- InteractionIdentity.tidyB2 %>%
mutate(Name = dplyr::recode(Name, "AgeGroup" = "Age", "ethnicity" = "Ethnicity", "HomeStatus"="Home Status",  "income" = "Income", "HomeStatus"="Home Status", "region" = "Region", "religion" = "Religion", "subClass" = "Subjective class", "subFamClass" = "Subjective family Class"))
P.Homophily.4<-ggplot(InteractionIdentity.tidyB2, aes(x=Name, y=exp(Coefficient), col=Referendum.Vote)) +
geom_errorbar(aes(ymin=exp(Coefficient-2*SE), ymax=exp(Coefficient+2*SE)), width=.2, position = position_dodge(width = 0.5)) +
geom_point(shape=19, size=2, position = position_dodge(width = 0.5)) +
geom_hline(yintercept=1, linetype="dashed",
size=1, color="grey", alpha=0.5)+
theme_clean()+
labs(color = "EU referendum") +
theme(plot.title = element_text(hjust = 0.5, face = "plain")) +
xlab("") + ylab("")+
coord_flip(ylim = c(0, 4))+
facet_grid(Name~., scales="free", space = "free")+
theme(strip.text.y = element_blank())+
scale_color_manual(values= c("#12B6CF", "#ffd700"), guide = guide_legend(reverse=TRUE))
Homophily.model.linear <- lm(ChoiceN~Match.GenderD+Match.EducationD+Match.subClassD+Match.subFamClassD+Match.HomeStatusD+
Match.regionD+Match.religionD+Match.ethnicityD+Match.incomeD+Match.AgeGroupD
, weights=data.experiment2.Second$W8, data = data.experiment2.Second)
Homophily1 <- coef(summary(Homophily.model.linear)) %>%
data.frame() %>%
tibble::rownames_to_column("term")
Homophily1 <- Homophily1 %>%
filter(term != "(Intercept)")
Homophily1<- Homophily1 %>%
mutate(term = dplyr::recode(term, "Match.AgeGroupD" = "Age", "Match.EducationD" = "Education",
"Match.ethnicityD" = "Ethnicity", "Match.incomeD" = "Income", "Match.GenderD" = "Gender",
"Match.HomeStatusD" = "HomeStatus", "Match.regionD" = "Region",
"Match.religionD" = "Religion", "Match.subClassD" = "Subjective class",
"Match.subFamClassD" = "Subjective family Class"))
Homophily1 <- Homophily1 %>%
mutate(term = fct_rev(term))
P.Homophily.linear.1<-ggplot(Homophily1, aes(x=term, y=Estimate)) +
geom_errorbar(aes(ymin=Estimate-2*Std..Error, ymax=Estimate+2*Std..Error), width=.1) +
geom_point(shape=19, size=1.5, alpha=0.7) +
geom_hline(yintercept=0, linetype="dashed",
size=1, color="blue", alpha=0.5)+
theme_clean()+
theme(plot.title = element_text(hjust = 0.5, face = "plain")) +
xlab("") + ylab("")+
coord_flip(ylim = c(-1, 1))+
theme(legend.position = "none")
One_At_A_Time_linear <- function(varind){
model<- lm(paste("ChoiceN~",varind),
weights=data.experiment2.Second$w8, data=data.experiment2.Second)
M<-model %>%
summary() %>%
coef() %>%
data.frame() %>%
tibble::rownames_to_column("Name") %>%
filter(Name == varind) %>%
textshape::column_to_rownames("Name") %>%
select(Estimate, Std..Error)
return(M)
}
One_At_A_Time_linear("Match.GenderD")
OneAtTime<-data.frame(matrix(NA, 10,2))
rownames(OneAtTime)<-c("Match.GenderD", "Match.EducationD", "Match.subClassD", "Match.subFamClassD", "Match.HomeStatusD",
"Match.regionD", "Match.religionD", "Match.ethnicityD", "Match.incomeD", "Match.AgeGroupD")
for (i in rownames(OneAtTime)){
OneAtTime[i,1:2]<-  One_At_A_Time_linear(i)
}
colnames(OneAtTime)[c(1,2)]<-c("Value","Std.Error")
OneAtTime<- OneAtTime %>%
tibble::rownames_to_column("Name")
OneAtTime<- OneAtTime %>%
mutate(Name = dplyr::recode(Name, "Match.AgeGroupD" = "Age", "Match.EducationD" = "Education",
"Match.ethnicityD" = "Ethnicity", "Match.incomeD" = "Income", "Match.GenderD" = "Gender",
"Match.HomeStatusD" = "HomeStatus", "Match.regionD" = "Region",
"Match.religionD" = "Religion", "Match.subClassD" = "Subjective class",
"Match.subFamClassD" = "Subjective family Class"))
P.OneAtTime.linear.1<-ggplot(OneAtTime, aes(x=Name, y=Value)) +
geom_errorbar(aes(ymin=Value-2*Std.Error, ymax=Value+2*Std.Error), width=.1) +
geom_point(shape=19, size=1.5, alpha=0.7) +
geom_hline(yintercept=0, linetype="dashed",
size=1, color="blue", alpha=0.5)+
theme_clean()+
xlab("") + ylab("")+
coord_flip(ylim = c(-1, 1))+
theme(legend.position = "none",
strip.text.y = element_blank(), panel.background = element_rect(fill="#00000000"))+
facet_grid(Name~., scale="free", space= "free")
#Interaction Party/EU
Homophily.PartyBrexit.ordinal<- polr(ChoiceNFactor~Match.GenderD*pastvote_Brexit*pastvote_party+
Match.EducationD*pastvote_Brexit*pastvote_party+
Match.subClassD*pastvote_Brexit*pastvote_party+
Match.subFamClassD*pastvote_Brexit*pastvote_party+
Match.HomeStatusD*pastvote_Brexit*pastvote_party+
Match.regionD*pastvote_Brexit*pastvote_party+
Match.religionD*pastvote_Brexit*pastvote_party+
Match.ethnicityD*pastvote_Brexit*pastvote_party+
Match.incomeD*pastvote_Brexit*pastvote_party+
Match.AgeGroupD*pastvote_Brexit*pastvote_party,
weights=data.experiment2.Second$W8, data = data.experiment2.Second,
Hess = T)
Cov.Education<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.EducationD")
Cov.Ethnicity<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.ethnicityD")
Cov.Home<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.HomeStatusD")
Cov.Gender<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.GenderD")
Cov.Region<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.regionD")
Cov.Religion<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.religionD")
Cov.Class<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.subClassD")
Cov.Age<-CovInteraction(Homophily.PartyBrexit.ordinal, "Match.AgeGroupD")
Cov.Income<- CovInteraction(Homophily.PartyBrexit.ordinal, "Match.incomeD")
Cov.FamilyClass <- CovInteraction(Homophily.PartyBrexit.ordinal, "Match.subFamClassD")
Homophily5 <- coef(summary(Homophily.PartyBrexit.ordinal)) %>%
data.frame() %>%
tibble::rownames_to_column("term")
Covariances<-rbind(Cov.Education, Cov.Ethnicity,
Cov.Home, Cov.Gender, Cov.Region, Cov.Religion, Cov.Class,Cov.FamilyClass, Cov.Age, Cov.Income)
InteractionIdentityPB<- left_join(Covariances, Homophily5, by = "term")
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(term = str_replace(term,"Match.GenderD:pastvote_partyLabour", "pastvote_partyLabour:Match.GenderD"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(term = str_replace(term,"Match.GenderD:pastvote_BrexitLeave", "pastvote_BrexitLeave:Match.GenderD"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(term = str_replace(term,"pastvote_BrexitLeave:Match.GenderD:pastvote_partyLabour", "pastvote_BrexitLeave:pastvote_partyLabour:Match.GenderD"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(term, Coefficient = str_glue("Conservative.Remain:{term}"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(Coefficient = str_remove(Coefficient, "Remain:pastvote_Brexit"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(Coefficient = str_replace(Coefficient,"Conservative.Remain:pastvote_partyLabour", "Labour.Remain"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate( Coefficient = str_replace(Coefficient,"Conservative.Leave:pastvote_partyLabour", "Labour.Leave"))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(Coefficient = str_remove(Coefficient,"Match."))
InteractionIdentityPB<- InteractionIdentityPB %>%
mutate(Coefficient = str_remove(Coefficient,"D"))
#Obtain coefficents
InteractionIdentityCoefPB<- InteractionIdentityPB %>%
dplyr::select(Coefficient, Value)
InteractionIdentityCoefPB<- InteractionIdentityCoefPB %>%
tidyr::separate(col=Coefficient, into=c("type","Coefficient"), sep=":")
InteractionIdentityCoefPB<- InteractionIdentityCoefPB %>%
tidyr::spread(type, Value, convert=T)
InteractionIdentityCoefPB<- InteractionIdentityCoefPB %>%
mutate(Conservative.Leave= InteractionIdentityCoefPB$Conservative.Remain + InteractionIdentityCoefPB$Conservative.Leave)
InteractionIdentityCoefPB<- InteractionIdentityCoefPB %>%
mutate(Labour.Leave= InteractionIdentityCoefPB$Conservative.Remain + InteractionIdentityCoefPB$Labour.Leave)
InteractionIdentityCoefPB<- InteractionIdentityCoefPB %>%
mutate(Labour.Remain= InteractionIdentityCoefPB$Conservative.Remain + InteractionIdentityCoefPB$Labour.Remain)
#Obtain standard errors
InteractionIdentityCovPB<- InteractionIdentityPB %>%
dplyr::select(Coefficient, Covariance)
InteractionIdentityCovPB<- InteractionIdentityCovPB %>%
tidyr::separate(col=Coefficient, into=c("type", "Coefficient"), sep=":")
InteractionIdentityCovPB<- InteractionIdentityCovPB %>%
tidyr::spread(type, Covariance, convert=T)
InteractionIdentityCovPB<- InteractionIdentityCovPB %>%
dplyr::rename("Conservative.Remain.Cov00"= "Conservative.Remain" ,
"Conservative.Leave.Cov01"= "Conservative.Leave" ,
"Labour.Leave.Cov02"= "Labour.Leave" ,
"Labour.Remain.Cov03" ="Labour.Remain")
InteractionIdentitySEPB<- InteractionIdentityPB %>%
dplyr::select(Coefficient, Std..Error)
InteractionIdentitySEPB<- InteractionIdentitySEPB %>%
tidyr::separate(col=Coefficient, into=c("type", "Coefficient"), sep=":")
InteractionIdentitySEPB<- InteractionIdentitySEPB %>%
tidyr::spread(type, Std..Error, convert=T)
InteractionIdentitySEPB<- InteractionIdentitySEPB %>%
dplyr::rename("Conservative.Remain.SE" = "Conservative.Remain" ,
"Conservative.Leave.SE" = "Conservative.Leave",
"Labour.Leave.SE" ="Labour.Leave",
"Labour.Remain.SE" ="Labour.Remain")
InteractionIdentitySE.tidyPB<- left_join(InteractionIdentitySEPB, InteractionIdentityCovPB, by = "Coefficient")
InteractionIdentitySE.tidyPB[,c(2,4,5)]<-InteractionIdentitySE.tidyPB[,c(2,4,5)]^2
InteractionIdentitySE.tidyPB[,c(6,8,9)]<-InteractionIdentitySE.tidyPB[,c(6,8,9)]*2
InteractionIdentitySE.tidyPB<- InteractionIdentitySE.tidyPB %>%
mutate(Conservative.Leave.SE=
sqrt( InteractionIdentitySE.tidyPB$Conservative.Remain.Cov00 +InteractionIdentitySE.tidyPB$Conservative.Leave.SE + InteractionIdentitySE.tidyPB$Conservative.Leave.Cov01))
InteractionIdentitySE.tidyPB<- InteractionIdentitySE.tidyPB %>%
mutate(Labour.Remain.SE=
sqrt(InteractionIdentitySE.tidyPB$Conservative.Remain.Cov00 +InteractionIdentitySE.tidyPB$Labour.Remain.SE + InteractionIdentitySE.tidyPB$Labour.Remain.Cov03))
InteractionIdentitySE.tidyPB<- InteractionIdentitySE.tidyPB %>%
mutate(Labour.Leave.SE=
sqrt(InteractionIdentitySE.tidyPB$Conservative.Remain.Cov00 +InteractionIdentitySE.tidyPB$Labour.Leave.SE + InteractionIdentitySE.tidyPB$Labour.Leave.Cov02))
#Tyding up
InteractionIdentitySE.tidyPB <- InteractionIdentitySE.tidyPB %>%
dplyr::select( "Name"=Coefficient, ends_with("SE"))
InteractionIdentitySE.tidyPB <- InteractionIdentitySE.tidyPB %>%
gather(key="level", value = "SE", ends_with("SE"))
InteractionIdentitySE.tidyPB <- InteractionIdentitySE.tidyPB %>%
mutate(level = str_remove(level, ".SE"))
InteractionIdentitySE.tidyPB <- InteractionIdentitySE.tidyPB %>%
unite("Name", c(Name, level))
InteractionIdentitySE.tidyPB <- InteractionIdentitySE.tidyPB %>%
filter(!is.na(SE))
InteractionIdentityCoef.tidyPB <- InteractionIdentityCoefPB %>%
dplyr::select( "Name"=Coefficient, everything())
InteractionIdentityCoef.tidyPB <- InteractionIdentityCoef.tidyPB %>%
gather(key="level", value = "Coefficient", Conservative.Leave:Labour.Remain)
InteractionIdentityCoef.tidyPB <- InteractionIdentityCoef.tidyPB %>%
unite("Name", c(Name, level))
InteractionIdentityCoef.tidyPB <- InteractionIdentityCoef.tidyPB %>%
filter(!is.na(Coefficient))
InteractionIdentity.tidyPB <- left_join(InteractionIdentitySE.tidyPB, InteractionIdentityCoef.tidyPB, by = "Name")
InteractionIdentity.tidyPB <-InteractionIdentity.tidyPB[order(InteractionIdentity.tidyPB$Name),]
InteractionIdentity.tidyPB2<- InteractionIdentity.tidyPB %>%
tidyr::separate(col=Name, into=c("Name","Party_EU"), sep="_")
InteractionIdentity.tidyPB2<- InteractionIdentity.tidyPB2 %>%
mutate(Name = dplyr::recode(Name, "AgeGroup" = "Age", "ethnicity" = "Ethnicity",  "income" = "Income", "HomeStatus"="Home Status"
, "region" = "Region", "religion" = "Religion", "subClass" = "Subjective class", "subFamClass" = "Subjective Family Class"))
P.Homophily.5<-ggplot(InteractionIdentity.tidyPB2, aes(x=Name, y=exp(Coefficient), col=Party_EU)) +
geom_errorbar(aes(ymin=exp(Coefficient-2*SE), ymax=exp(Coefficient+2*SE)), width=.2, position = position_dodge(width = 0.5)) +
geom_point(shape=19, size=2, position = position_dodge(width = 0.5)) +
geom_hline(yintercept=1, linetype="dashed",
size=1, color="grey", alpha=0.5)+
theme_clean()+
scale_color_discrete(name = "EU referendum and General Election", labels = c("Conservative Leave", "Conservative Remain", "Labour Leave", "Labour Remian")) +
theme(plot.title = element_text(hjust = 0.5, face = "plain")) +
xlab("") + ylab("")+
coord_flip(ylim =c(0,5) )+
facet_grid(Name~., scales="free", space = "free")+
#  scale_y_continuous(trans="log10")+
theme(strip.text.y =  element_blank())
options(knitr.kable.NA = '')
kable(read.csv("Levels.csv", fileEncoding = "UTF-8-BOM"), format="latex", caption = "\\label{tab:Levels}Levels used for each attribute of profiles",  booktabs = T, escape = TRUE)
library(papeR)
Respondent <- data.experiment2.Second %>%
distinct(ID, .keep_all= TRUE) %>%
dplyr::mutate(
BESPanel.profile_gross_household = str_remove(BESPanel.profile_gross_household," per year"),
BESPanel.profile_gross_household = as.factor(str_remove_all(BESPanel.profile_gross_household,"Â"))
)%>%
select("Age"=Age.respondent, "Ethnicity"=Ethnicity_Respondent ,"Annual Income"=BESPanel.profile_gross_household ,"Religion"=BESPanel.profile_religion2 ,"Home Status" = BESPanel.profile_house_tenure,"Class"=subjClass.RespondentClass ,"Education"= educ5,"Gender"=profile_gender,"Region" = profile_GOR)
ProfileB <- data.experiment2.Second %>%
select("Age"=AgeB, "Ethnicity"=EthnicityB ,"Annual_Income"=Anual_Household_IncomeB ,"Religion"=ReligionB ,"Home Status" = Home_statusB,"Class"=Sub_ClassB, "Family Class" = Sub_Fam_ClassB, "Education"= EducationB,"Gender"=GenderB,"Region" = RegionB)
ProfileA <- data.experiment2.Second %>%
select("Age"=AgeA, "Ethnicity"=EthnicityA ,"Annual_Income"=Anual_Household_IncomeA ,"Religion"=ReligionA ,"Home Status" = Home_statusA,"Class"=Sub_ClassA, "Family Class" = Sub_Fam_ClassA, "Education"= EducationA,"Gender"=GenderA,"Region" = RegionA)
Profile <- rbind(ProfileA,ProfileB)
Profile <- Profile %>%
mutate(
Ethnicity = dplyr::recode(Ethnicity, "The person's ethnicity is unknown" = "Unknown"),
Annual_Income =as.factor(str_remove(string=Annual_Income, pattern="Household income is ")),
Religion = dplyr::recode(Religion, "The person's religion is unknown" = "Unknown"),
Gender = dplyr::recode(as.factor(Gender),"1" = "Female", "0" = "Male"),
Education = dplyr::recode(as.factor(Education),"1" = "University", "0" = "Not University")
)
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Respondent,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "grid",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:Descriptive}Descriptive statistics for respondents",
tmp.img.dir  = "/tmp")
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Profile,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "grid",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:DescriptiveProf}Descriptive statistics for profiles",
tmp.img.dir  = "/tmp")
grid.arrange(P.Homophily.linear.1, P.OneAtTime.linear.1, nrow=2)
Levels <- data.frame(
term = c("Gender", "Education", "Subjective class",
"Subjective family Class", "HomeStatus", "Region", "Religion",
"Ethnicity", "Income"),
Levels = c(2, 2, 2, 2, 2, 11, 9, 5, 8)
)
Levels_vs_Estimates<-left_join(Homophily1, Levels, b=c("term")) %>%
filter(term !="Age") %>%
mutate(
term = str_replace(as.character(term), "Subjective class", "Class")) %>%
mutate(
term = str_replace(as.character(term), "Subjective family Class", "Family Class")
)
P.Levels_Vs_Estimates <- ggplot(Levels_vs_Estimates, aes(x=as.factor(Levels), y=exp(Estimate))) +
geom_point(shape=19, size=3) +
ggrepel::geom_text_repel(aes(y = exp(Estimate), label=term))+
theme_clean()+
theme(plot.title = element_text(hjust = 0.5, face = "plain")) +
xlab("Levels") + ylab("Coefficent Estimate")+
theme(legend.position = "none")
data.experiment2.Second <- data.experiment2.Second %>%
mutate(
Threshold0A = Closeness.AgeA < 1,
Threshold0B = Closeness.AgeB < 1,
Threshold5A = Closeness.AgeA < 5,
Threshold5B = Closeness.AgeB < 5,
Threshold10A = Closeness.AgeA < 10,
Threshold10B = Closeness.AgeB < 10,
Threshold15A = Closeness.AgeA < 15,
Threshold15B = Closeness.AgeB < 15,
Threshold20A = Closeness.AgeA < 20,
Threshold20B = Closeness.AgeB < 20
)
data.experiment2.Second <- data.experiment2.Second %>%
mutate(
Threshold_None = case_when(
Threshold0A == 1 & Threshold0B == 0 ~ 1,
Threshold0A == 0 & Threshold0B == 1 ~ -1,
TRUE ~ 0),
Threshold_5 = case_when(
Threshold5A == 1 & Threshold5B == 0 ~ 1,
Threshold5A == 0 & Threshold5B == 1 ~ -1,
TRUE ~ 0),
Threshold_10 = case_when(
Threshold10A == 1 & Threshold10B == 0 ~ 1,
Threshold10A == 0 & Threshold10B == 1 ~ -1,
TRUE ~ 0),
Threshold_15 = case_when(
Threshold15A == 1 & Threshold15B == 0 ~ 1,
Threshold15A == 0 & Threshold15B == 1 ~ -1,
TRUE ~ 0),
Threshold_20 = case_when(
Threshold20A == 1 & Threshold20B == 0 ~ 1,
Threshold20A == 0 & Threshold20B == 1 ~ -1,
TRUE ~ 0),
)
Age_Op <- function(varind){
model<- polr(paste("ChoiceNFactor~",varind),
weights=data.experiment2.Second$w8, data=data.experiment2.Second, Hess = T )
M<-data.frame(coef(summary(model))[1,1])
M[1,2]<-data.frame(coef(summary(model))[1,2])
rownames(M)[1]<-varind
colnames(M)[1]<-"Value"
colnames(M)[2]<-"Std. Error"
return(M)
}
AgeOp<-data.frame(matrix(NA, 5,2))
rownames(AgeOp)<-c("Threshold_None","Threshold_5","Threshold_10","Threshold_15","Threshold_20")
for (i in rownames(AgeOp)){
AgeOp[i,1:2]<-  Age_Op(i)
}
colnames(AgeOp)[c(1,2)]<-c("Value","Std.Error")
AgeOp<- AgeOp %>%
tibble::rownames_to_column("Name")
P.AgeOp<-ggplot(AgeOp, aes(x=Name, y=exp(Value))) +
geom_errorbar(aes(ymin=exp(Value-2*Std.Error), ymax=exp(Value+2*Std.Error)), width=.1) +
geom_point(shape=19, size=2, alpha=0.7) +
geom_hline(yintercept=1, linetype="dashed",
size=1, color="blue", alpha=0.5)+
theme_clean()+
theme(plot.title = element_text(hjust = 0.5, face = "plain")) +
xlab("") + ylab("")+
coord_flip(ylim = c(-1, 3))+
theme(legend.position = "none",
strip.text.y = element_blank(), panel.background = element_rect(fill="#00000000"))+
facet_grid(fct_relevel(Name, "Threshold_None", "Threshold_5", "Threshold_10", "Threshold_15", "Threshold_20")~., scale="free", space= "free")
P.Sensitivity
P.Levels_Vs_Estimates
P.AgeOp
P.Homophily.2
P.Homophily.By.Class
P.Homophily.5
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Respondent,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "grid",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:Descriptive}Descriptive statistics for respondents",
tmp.img.dir  = "/tmp")
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Profile,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "grid",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:DescriptiveProf}Descriptive statistics for profiles",
tmp.img.dir  = "/tmp")
?summarytools
?dfsummary
?dfSummary
install.packages("summarytools")
install.packages("summarytools")
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Profile,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "grid",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:DescriptiveProf}Descriptive statistics for profiles",
tmp.img.dir  = "/tmp")
install.packages("summarytools")
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Profile,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "rmarkdown",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:DescriptiveProf}Descriptive statistics for profiles",
tmp.img.dir  = "/tmp")
summarytools::define_keywords(duplicates = "", n="", title.dfSummary = "")
summarytools::dfSummary(Profile,
max.distinct.values = 25,
display.labels = FALSE,
plain.ascii  = FALSE,
style        = "multiline",
graph.magnif = 0.75,
valid.col    = FALSE,
graph.col = FALSE,
na.col = FALSE,
varnumbers = FALSE,
caption = "\\label{tab:DescriptiveProf}Descriptive statistics for profiles",
tmp.img.dir  = "/tmp")
install.packages("gtsummary")
gtsummary::tbl_summary(Profile)
gtsummary::tbl_summary(Profile)%>%
as_kable_extra()
gtsummary::tbl_summary(Profile)%>%
kableExtra::as_kable_extra(format = "latex")
library(gtsummary)
